﻿package com.kiklink.model.util;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.kiklink.model.domain.AdProduct;
import com.kiklink.model.domain.Coach;
import com.kiklink.model.domain.Comment;
import com.kiklink.model.domain.Favorite;
import com.kiklink.model.domain.KiklinkMessage;
import com.kiklink.model.domain.MyProduct;
import com.kiklink.model.domain.Order;
import com.kiklink.model.domain.Page;
import com.kiklink.model.domain.Product;
import com.kiklink.model.domain.Shop;
import com.kiklink.model.domain.TransactionRecord;
import com.kiklink.model.domain.User;

public class JsonToObject {
	public static final String IMG_URL_PREFIX="http://www.kiklink.com:8080";
	public static Coach JsonToCoach(JSONObject jObject) {
		Coach coach = new Coach();
		coach.setAddition(jObject.optString("addition"));
		coach.setBirthDate(jObject.optInt("birthDate"));
		coach.setBirthMonth(jObject.optInt("birthMonth"));
		coach.setBirthYear(jObject.optInt("birthYear"));
		coach.setCreateUser(jObject.optString("createUser"));
		coach.setCreatetimelong(jObject.optLong("createtimelong"));
		coach.setCreateuser(jObject.optInt("createuser"));
		coach.setId(jObject.optInt("id"));
		coach.setModifytimelong(jObject.optLong("modifytimelong"));
		coach.setModifyuser(jObject.optInt("modifyuser"));
		coach.setName(jObject.optString("name"));
		if (jObject.optString("photo").length()>2) {
			coach.setPhoto(IMG_URL_PREFIX+jObject.optString("photo"));
		}
		else {
			coach.setPhoto(jObject.optString("photo"));
		}
		coach.setProfile(jObject.optString("profile"));
		coach.setSex(jObject.optInt("sex"));
		coach.setShopId(jObject.optInt("shopId"));
		coach.setStatus(jObject.optInt("status"));

		return coach;

	}

	public static Shop JsonToShop(JSONObject jObject) {
		// TODO Auto-generated method stub
		Shop shop = new Shop();
		shop.setAddition(jObject.optString("addition"));
		shop.setAddress(jObject.optString("address"));
		shop.setBankName(jObject.optString("bankname"));
		shop.setBankNumber(jObject.optString("banknumber"));
		shop.setBankOpenname(jObject.optString("bankopenname"));
		shop.setBirthDate(jObject.optInt("birthDate"));
		shop.setBirthMonth(jObject.optInt("birthMonth"));
		shop.setBirthYear(jObject.optInt("birthYear"));
		shop.setCity(jObject.optString("city"));
		shop.setCityId(jObject.optInt("cityid"));
		shop.setClassTable(jObject.optString("classtable"));
		shop.setComment(jObject.optString("comment"));
		shop.setCompanyName(jObject.optString("companyName"));
		shop.setCreateDate(jObject.optString("createDate"));
		shop.setCreateUser(jObject.optString("createUser"));
		shop.setCreatetimelong(jObject.optLong("createtimelong"));
		shop.setCreateuser(jObject.optInt("createuser"));
		shop.setCustomType(jObject.optString("customtype"));
		shop.setEmail(jObject.optString("email"));
		shop.setExt6(jObject.optString("ext6"));
		shop.setExt7(jObject.optString("ext7"));
		shop.setExt8(jObject.optString("ext8"));
		shop.setExt9(jObject.optString("ext9"));
		shop.setExt10(jObject.optString("ext10"));
		shop.setFlowerPercent(jObject.optInt("flowerPercent"));
		shop.setId(jObject.optInt("id"));
		shop.setIdNumber(jObject.optString("idNumber"));
		shop.setIdPictureBack(jObject.optString("idPcitureBack"));
		shop.setIdPicture(jObject.optString("idPicture"));
		shop.setIntroduction(jObject.optString("introduction"));
		shop.setLogo(jObject.optString("logo"));
		if (jObject.optString("mapimg").length()>2) {
			shop.setMapImg(IMG_URL_PREFIX+jObject.optString("mapimg"));
		}
		else {
			shop.setMapImg(jObject.optString("mapimg"));
		}
		shop.setMapx(jObject.optDouble("mapx"));
		shop.setMapy(jObject.optDouble("mapy"));
		shop.setModifytimelong(jObject.optLong("modifytimelong"));
		shop.setModifyuser(jObject.optInt("modifyuser"));
		shop.setMoreService(jObject.optString("moreservice"));
		shop.setOrgNumber(jObject.optString("orgNumber"));
		shop.setPassportPicture(jObject.optString("passportPicture"));
		shop.setPhoneNo(jObject.optString("phoneno"));
		shop.setPointAppointmentSuccessful(jObject
				.optInt("pointAppointmentSuccessful"));
		shop.setPointDescriptionMatch(jObject.optInt("pointDescriptionMatch"));
		shop.setPointPerfational(jObject.optInt("pointPerfational"));
		shop.setPointServiceAttitude(jObject.optInt("pointServiceAttitude"));
		shop.setPostcode(jObject.optString("postcode"));
		shop.setProfile(jObject.optString("profile"));
		shop.setProvince(jObject.optString("province"));
		shop.setProvinceId(jObject.optInt("provinceid"));
		shop.setQu(jObject.optString("qu"));
		shop.setQuId(jObject.optInt("quid"));
		shop.setRealName(jObject.optString("realName"));
		shop.setSavedCount(jObject.optInt("savedCount"));
		shop.setServedClients(jObject.optInt("servedClients"));
		shop.setSex(jObject.optInt("sex"));
		shop.setShopName(jObject.optString("shopName"));
		shop.setShopType(jObject.optInt("shoptype"));
		shop.setStatus(jObject.optInt("status"));
		shop.setSuggestReason(jObject.optString("suggestreason"));
		shop.setTemplate(jObject.optString("template"));
		shop.setTemplateId(jObject.optInt("templateId"));
		shop.setUserType(jObject.optInt("userType"));
		shop.setUserid(jObject.optInt("userid"));
		if (jObject.optString("weiboimg").length()>2) {
			shop.setWeiboImg(IMG_URL_PREFIX+jObject.optString("weiboimg"));
		}
		else {
			shop.setWeiboImg(jObject.optString("weiboimg"));
		}
		if (jObject.optString("weixinimg").length()>2) {
			shop.setWeixinImg(IMG_URL_PREFIX+jObject.optString("weixinimg"));
		}
		else {
			shop.setWeixinImg(jObject.optString("weixinimg"));
		}

		JSONArray jArray = jObject.optJSONArray("products");

		List<Product> productList = new ArrayList<Product>();
		if (jArray == null) {
			shop.setProductList(productList);
			return shop;
		}
		for (int i = 0; i < jArray.length(); i++) {
			JSONObject jObject1 = jArray.optJSONObject(i);
			if (jObject1 == null)
				continue;
			Product product = JsonToProduct(jObject1);
			if (product == null)
				continue;
			productList.add(product);
		}
		shop.setProductList(productList);

		return shop;
	}

	public static Product JsonToProduct(JSONObject jObject) {
		Product product = new Product();
		product.setAddition(jObject.optString("addition"));
		product.setAllConsulting(jObject.optInt("allConsulting"));
		product.setBuyedCount(jObject.optInt("buyedCount"));
		product.setCategoryId(jObject.optInt("categoryid"));
		product.setCity(jObject.optString("city"));
		product.setCityId(jObject.optInt("cityid"));
		product.setClassCount(jObject.optInt("classCount"));
		product.setComment(jObject.optString("comment"));
		product.setCreateUser(jObject.optString("createUser"));
		product.setCreatetimelong(jObject.optLong("createtimelong"));
		product.setCreateuser(jObject.optInt("createuser"));
		product.setDescription(jObject.optString("description"));
		product.setEggCount(jObject.optInt("eggCount"));
		product.setExt1(jObject.optString("ext1"));
		product.setExt2(jObject.optString("ext2"));
		product.setExt3(jObject.optString("ext3"));
		product.setExt4(jObject.optString("ext4"));
		product.setExt5(jObject.optString("ext5"));
		product.setExt6(jObject.optString("ext6"));
		product.setExt7(jObject.optString("ext7"));
		product.setExt8(jObject.optString("ext8"));
		product.setExt9(jObject.optString("ext9"));
		product.setExt10(jObject.optDouble("ext10"));
		product.setExtInt1(jObject.optInt("extInt1"));
		product.setExtInt2(jObject.optInt("extInt2"));
		product.setExtInt3(jObject.optInt("extInt3"));
		product.setExtInt4(jObject.optInt("extInt4"));
		product.setExtInt5(jObject.optInt("extInt5"));
		product.setFlowerCount(jObject.optInt("flowerCount"));
		product.setFreeConsulting(jObject.optInt("freeConsulting"));
		product.setGotoHome(jObject.optInt("gotoHome"));
		product.setId(jObject.optInt("id"));
		product.setMapx(jObject.optDouble("mapx"));
		product.setMapy(jObject.optDouble("mapy"));
		product.setMiddleCount(jObject.optInt("middleCount"));
		product.setModifytimelong(jObject.optLong("modifytimelong"));
		product.setModifyuser(jObject.optInt("modifyuser"));
		product.setName(jObject.optString("name"));
		product.setPerClassMinutes(jObject.optInt("perClassMinutes"));
		if (jObject.optString("photo").length()>2) {
			product.setPhoto(IMG_URL_PREFIX+jObject.optString("photo"));
		}
		else {
			product.setPhoto(jObject.optString("photo"));
		}
		product.setPlaceAddition(jObject.optString("placeAddition"));
		product.setPlacePriceInclued(jObject.optInt("placePriceInclued"));
		product.setPrice(jObject.optInt("price"));
		product.setProvince(jObject.optString("province"));
		product.setProvinceId(jObject.optInt("provinceid"));
		product.setQu(jObject.optString("qu"));
		product.setQuId(jObject.optInt("quid"));
		product.setQuan(jObject.optString("quan"));
		product.setQuanId(jObject.optInt("quanid"));
		product.setReturnClassCount(jObject.optInt("returnClassCount"));
		product.setSavedCount(jObject.optInt("savedCount"));
		product.setShopId(jObject.optInt("shopId"));
		product.setStatus(jObject.optInt("status"));
		product.setSubname(jObject.optString("subname"));
		product.setTags(jObject.optString("tags"));
		product.setTeachType(jObject.optInt("teachType"));
		product.setTemplate(jObject.optString("template"));
		product.setTemplateId(jObject.optInt("templateId"));
		product.setValidDays(jObject.optInt("validDays"));
		return product;
	}

	public static Page JsonToPage(JSONObject jObject, String pagetype) {
		Page page = new Page();
		page.setDataJsonObject(jObject);

		page.setPagetype(pagetype);
		if (pagetype.equals("Coach")) {
			page=createDefaultPage(page);
			List<Coach> coachList = new ArrayList<Coach>();
			JSONArray jArray = jObject.optJSONArray("coaches");
			if (jArray == null) {
				page.setList(coachList);
				return page;
			}
			page.setThisPageLastElementNumber(jArray.length());
			page.setTotalCount(jArray.length());

			for (int i = 0; i < jArray.length(); i++) {

				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				Coach coach = JsonToObject.JsonToCoach(jObject1);
				if (coach == null)
					continue;
				coachList.add(coach);
			}
			page.setList(coachList);
			return page;
		} 
		else if (pagetype.equals("OrderShopping")) {
			page=createDefaultPage(page);
			
			List<Order> orderList = new ArrayList<Order>();
			JSONObject jObject2 = jObject.optJSONObject("order");
			if (jObject2 == null) {
				page.setList(orderList);
				return page;
			}
			Order order = JsonToObject.JsonToOrder(jObject2);
			if (order == null)
			{
				page.setList(orderList);
				return page;
			}
			orderList.add(order);
			page.setThisPageLastElementNumber(1);
			page.setTotalCount(1);

			
			page.setList(orderList);
			return page;
		}
		else if (pagetype.equals("SetFavorite")) {
			page=createDefaultPage(page);
			
			List<Favorite> favoriteList = new ArrayList<Favorite>();
			JSONObject jObject2 = jObject.optJSONObject("save");
			if (jObject2 == null) {
				page.setList(favoriteList);
				return page;
			}
			Favorite favorite = JsonToObject.JsonToFavorite(jObject2);
			if (favorite == null)
			{
				page.setList(favoriteList);
				return page;
			}
			favoriteList.add(favorite);
			page.setThisPageLastElementNumber(1);
			page.setTotalCount(1);

			
			page.setList(favoriteList);
			return page;
		}else if (pagetype.equals("AdProduct")) {
			page=createDefaultPage(page);
			List<AdProduct> adProductList = new ArrayList<AdProduct>();
			JSONArray jArray = jObject.optJSONArray("rows");
			if (jArray == null) {
				page.setList(adProductList);
				return page;
			}
			page.setThisPageLastElementNumber(jArray.length());
			page.setTotalCount(jArray.length());

			for (int i = 0; i < jArray.length(); i++) {

				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				AdProduct adProduct = JsonToObject.JsonToAdProduct(jObject1);
				if (adProduct == null)
					continue;
				adProductList.add(adProduct);
			}
			page.setList(adProductList);
			return page;
		} else if (pagetype.equals("TransactionRecord")) {
			JSONObject jObjectPage = jObject.optJSONObject("page");
			page.setFirstPage(jObjectPage.optBoolean("firstPage"));
			page.setFirstResult(jObjectPage.optInt("firstResult"));
			page.setHasNextPage(jObjectPage.optBoolean("hasNextPage"));
			page.setHasPreviousPage(jObjectPage.optBoolean("hasPreviousPage"));
			page.setLastPage(jObjectPage.optBoolean("lastPage"));
			page.setLastPageNumber(jObjectPage.optInt("lastPageNumber"));
			page.setLinkPageNumbers(jObjectPage.optString("linkPageNumbers"));
			page.setNextPageNumber(jObjectPage.optInt("nextPageNumber"));
			page.setPageSize(jObjectPage.optInt("pageSize"));
			page.setPreviousPageNumber(jObjectPage.optInt("previousPageNumber"));
			page.setThisPageFirstElementNumber(jObjectPage
					.optInt("thisPageFirstElementNumber"));
			page.setThisPageLastElementNumber(jObjectPage
					.optInt("thisPageLastElementNumber"));
			page.setThisPageNumber(jObjectPage.optInt("thisPageNumber"));
			page.setTotalCount(jObjectPage.optInt("totalCount"));
			page.setPagetype(pagetype);
			List<TransactionRecord> transactionRecordList = new ArrayList<TransactionRecord>();
			JSONArray jArray = jObject.optJSONArray("rows");
			if (jArray == null) {
				page.setList(transactionRecordList);
				return page;
			}
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				TransactionRecord transactionRecord = JsonToTransactionRecord(jObject1);
				if (transactionRecord == null)
					continue;
				transactionRecordList.add(transactionRecord);
			}
			page.setList(transactionRecordList);
			return page;
		}
		page.setFirstPage(jObject.optBoolean("firstPage"));
		page.setFirstResult(jObject.optInt("firstResult"));
		page.setHasNextPage(jObject.optBoolean("hasNextPage"));
		page.setHasPreviousPage(jObject.optBoolean("hasPreviousPage"));
		page.setLastPage(jObject.optBoolean("lastPage"));
		page.setLastPageNumber(jObject.optInt("lastPageNumber"));
		page.setLinkPageNumbers(jObject.optString("linkPageNumbers"));
		page.setNextPageNumber(jObject.optInt("nextPageNumber"));
		page.setPageSize(jObject.optInt("pageSize"));
		page.setPreviousPageNumber(jObject.optInt("previousPageNumber"));
		page.setThisPageFirstElementNumber(jObject
				.optInt("thisPageFirstElementNumber"));
		page.setThisPageLastElementNumber(jObject
				.optInt("thisPageLastElementNumber"));
		page.setThisPageNumber(jObject.optInt("thisPageNumber"));
		page.setTotalCount(jObject.optInt("totalCount"));
		page.setPagetype(pagetype);

		if (pagetype.equals("Comment")) {
			List<Comment> commentList = new ArrayList<Comment>();
			JSONArray jArray = jObject.optJSONArray("result");
			if (jArray == null) {
				page.setList(commentList);
				return page;
			}
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				Comment comment = JsonToComment(jObject1);
				if (comment == null)
					continue;
				commentList.add(comment);
			}
			page.setList(commentList);
		} else if (pagetype.equals("Product")) {
			List<Product> productList = new ArrayList<Product>();
			JSONArray jArray = jObject.optJSONArray("result");
			if (jArray == null) {
				page.setList(productList);
				return page;
			}
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				Product product = JsonToProduct(jObject1);
				if (product == null)
					continue;
				productList.add(product);
			}
			page.setList(productList);
		}

		else if (pagetype.equals("Order")) {
			List<Order> OrderList = new ArrayList<Order>();
			JSONArray jArray = jObject.optJSONArray("result");
			if (jArray == null) {
				page.setList(OrderList);
				return page;
			}
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				Order order = JsonToOrder(jObject1);
				if (order == null)
					continue;
				OrderList.add(order);
			}
			page.setList(OrderList);
		} else if (pagetype.equals("MyProduct")) {
			List<MyProduct> myProductList = new ArrayList<MyProduct>();
			JSONArray jArray = jObject.optJSONArray("result");
			if (jArray == null) {
				page.setList(myProductList);
				return page;
			}
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				MyProduct myProduct = JsonToMyProduct(jObject1);
				if (myProduct == null)
					continue;
				myProductList.add(myProduct);
			}
			page.setList(myProductList);
		}
		else if (pagetype.equals("Favorite")) {
			List<Favorite> favoriteList = new ArrayList<Favorite>();
			JSONArray jArray = jObject.optJSONArray("result");
			if (jArray == null) {
				page.setList(favoriteList);
				return page;
			}
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				
				JSONObject addJsonObject= jObject1.optJSONObject("addition");
				
				
				Favorite favorite = JsonToFavorite(jObject1);
				
				if (favorite == null)
					continue;
				
				if(addJsonObject!=null)
				{
					favorite.setPrice(addJsonObject.optInt("price"));
					favorite.setSubname(addJsonObject.optString("subname"));
				}

				favoriteList.add(favorite);
			}
			page.setList(favoriteList);
		}

		else if (pagetype.equals("KiklinkMessage")) {
			List<KiklinkMessage> kiklinkMessageList = new ArrayList<KiklinkMessage>();
			JSONArray jArray = jObject.optJSONArray("result");
			if (jArray == null) {
				page.setList(kiklinkMessageList);
				return page;
			}
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject jObject1 = jArray.optJSONObject(i);
				if (jObject1 == null)
					continue;
				KiklinkMessage kiklinkMessage = JsonToMessage(jObject1);
				if (kiklinkMessage == null)
					continue;
				kiklinkMessageList.add(kiklinkMessage);
			}
			page.setList(kiklinkMessageList);
		}

		return page;

	}

	private static Page createDefaultPage(Page page) {
		// TODO 自动生成的方法存根
		page.setFirstPage(true);
		page.setFirstResult(0);
		page.setHasNextPage(false);
		page.setHasPreviousPage(false);
		page.setLastPage(true);
		page.setLastPageNumber(1);
		page.setLinkPageNumbers("[1]");
		page.setNextPageNumber(2);
		page.setPageSize(10);
		page.setPreviousPageNumber(0);
		page.setThisPageFirstElementNumber(1);
		page.setThisPageNumber(1);
		page.setListclass();
		return page;
	}

	private static AdProduct JsonToAdProduct(JSONObject jObject) {
		// TODO Auto-generated method stub
		AdProduct adProduct = new AdProduct();
		String content = jObject.optString("content");
		
		int indexoftargettype = content.indexOf("targettype");
		int indexofid = content.indexOf("theid");
		int indexofimg = content.indexOf("img");
		int a = Integer.parseInt(content.substring(indexofid + "theid".length()
				+ 3, content.length() - 3));
		
		adProduct.setId(a);
		
		if (content.substring(indexofimg + "img".length() + 3,
				indexofid - 3).length()>2) {
			adProduct.setImg(IMG_URL_PREFIX+content.substring(indexofimg + "img".length() + 3,
					indexofid - 3));
		}
		else {
			adProduct.setImg(content.substring(indexofimg + "img".length() + 3,
					indexofid - 3));
		}
		
		adProduct.setTargettype(content.substring(indexoftargettype
				+ "targettype".length() + 3, indexofimg - 3));
		adProduct.setAddition(jObject.optString("addition"));
		adProduct.setCreateUser(jObject.optString("createUser"));
		adProduct.setCreatetimelong(jObject.optLong("createtimelong"));
		adProduct.setCreateuser(jObject.optInt("createuser"));
		adProduct.setModifytimelong(jObject.optLong("modifytimelong"));
		adProduct.setModifyuser(jObject.optInt("modifyuser"));

		return adProduct;
	}

	private static Comment JsonToComment(JSONObject jObject) {
		// TODO Auto-generated method stub
		Comment comment = new Comment();
		comment.setUserid(jObject.optInt("userid"));
		comment.setUsername(jObject.optString("username"));
		if (jObject.optString("userphoto").length()>2) {
			comment.setUserphoto(IMG_URL_PREFIX+jObject.optString("userphoto"));
		}
		else {
			comment.setUserphoto(jObject.optString("userphoto"));
		}
		comment.setTargetid(jObject.optInt("targetid"));
		comment.setComment(jObject.optString("comment"));
		comment.setPointdescription_match(jObject
				.optInt("pointdescription_match"));
		comment.setPointperfational(jObject.optInt("pointperfational"));
		comment.setPointserviceattitude(jObject.optInt("pointserviceattitude"));
		comment.setPoint(jObject.optInt("point"));
		comment.setPointappointmentsuccessful(jObject
				.optInt("pointappointmentsuccessful"));

		return comment;
	}

	public static User JsonToUser(JSONObject jObject) {
		// TODO Auto-generated method stub
		User user = new User();
		user.setAddition(jObject.optString("addition"));
		user.setAddress(jObject.optString("address"));
		user.setBirthDate(jObject.optInt("birthDate"));
		user.setBirthMonth(jObject.optInt("birthMonth"));
		user.setBirthYear(jObject.optInt("birthYear"));
		user.setCity(jObject.optString("city"));
		user.setCityId(jObject.optInt("cityid"));
		user.setCreateGroupCount(jObject.optInt("createGroupCount"));
		user.setCreateTopicCount(jObject.optInt("createTopicCount"));
		user.setCreateUser(jObject.optString("createUser"));
		user.setCreatetimelong(jObject.optLong("createtimelong"));
		user.setCreateuser(jObject.optInt("createuser"));
		user.setEmail(jObject.optString("email"));
		user.setId(jObject.optInt("id"));
		user.setJoinGroupCount(jObject.optInt("joinGroupCount"));
		user.setLastlogintime(jObject.optLong("lastlogintime"));
		user.setLogintoken(jObject.optString("logintoken"));
		user.setMobile(jObject.optString("mobile"));
		user.setModifytimelong(jObject.optLong("modifytimelong"));
		user.setModifyuser(jObject.optInt("modifyuser"));
		user.setOpenid(jObject.optString("openid"));
		user.setPasswd(jObject.optString("passwd"));
		user.setPhone(jObject.optString("phone"));
		if (jObject.optString("photo").length()>2) {
			user.setPhoto(IMG_URL_PREFIX+jObject.optString("photo"));
		}
		else {
			user.setPhoto(jObject.optString("photo"));
		}
		
		user.setPoints(jObject.optInt("points"));
		user.setPostCode(jObject.optString("postCode"));
		user.setProvince(jObject.optString("province"));
		user.setProvinceId(jObject.optInt("provinceid"));
		user.setQu(jObject.optString("qu"));
		user.setQuId(jObject.optInt("quid"));
		user.setRealName(jObject.optString("realName"));
		user.setReplyCount(jObject.optInt("replyCount"));
		user.setSex(jObject.optInt("sex"));
		user.setSource(jObject.optString("source"));
		user.setStatus(jObject.optInt("status"));
		user.setThirdType(jObject.optString("thirdType"));
		user.setUsername(jObject.optString("username"));
		user.setUserYype(jObject.optInt("usertype"));

		return user;
	}

	private static MyProduct JsonToMyProduct(JSONObject jObject) {
		// TODO Auto-generated method stub
		MyProduct myProduct = new MyProduct();
		myProduct.setAddition(jObject.optString("addition"));
		myProduct.setCity(jObject.optString("city"));
		myProduct.setClassCount(jObject.optInt("classCount"));
		myProduct.setClassType(jObject.optInt("classType"));
		myProduct.setCount(jObject.optInt("count"));
		myProduct.setCouponId(jObject.optInt("couponId"));
		myProduct.setCouponPrice(jObject.optInt("couponPrice"));
		myProduct.setCreateUser(jObject.optString("createUser"));
		myProduct.setCreatetimelong(jObject.optLong("createtimelong"));
		myProduct.setCreateuser(jObject.optInt("createuser"));
		myProduct.setExt1(jObject.optString("ext1"));
		myProduct.setExt2(jObject.optString("ext2"));
		myProduct.setExt3(jObject.optString("ext3"));
		myProduct.setExt4(jObject.optString("ext4"));
		myProduct.setExt5(jObject.optString("ext5"));
		myProduct.setExtInt1(jObject.optInt("extInt1"));
		myProduct.setExtInt2(jObject.optInt("extInt2"));
		myProduct.setExtInt3(jObject.optInt("extInt3"));
		myProduct.setExtInt4(jObject.optInt("extInt4"));
		myProduct.setExtInt5(jObject.optInt("extInt5"));
		myProduct.setHastrainsummary(jObject.optInt("hastrainsummary"));
		myProduct.setId(jObject.optInt("id"));
		myProduct.setModifytimelong(jObject.optLong("modifytimelong"));
		myProduct.setModifyuser(jObject.optInt("modifyuser"));
		myProduct.setOrderId(jObject.optInt("orderid"));
		myProduct.setPerPrice(jObject.optInt("perPrice"));
		myProduct.setPrice(jObject.optInt("price"));
		myProduct.setProductName(jObject.optString("productName"));
		myProduct.setProductId(jObject.optInt("productid"));
		myProduct.setProgress(jObject.optInt("progress"));
		myProduct.setShopName(jObject.optString("shopName"));
		myProduct.setShopid(jObject.optInt("shopid"));
		myProduct.setStatus(jObject.optInt("status"));
		myProduct.setUserid(jObject.optInt("userid"));
		return myProduct;
	}

	private static TransactionRecord JsonToTransactionRecord(JSONObject jObject) {
		// TODO Auto-generated method stub
		TransactionRecord transactionRecord = new TransactionRecord();
		transactionRecord.setAddition(jObject.optString("addition"));
		transactionRecord.setClassType(jObject.optInt("classType"));
		transactionRecord.setCount(jObject.optInt("count"));
		transactionRecord.setCreateUser(jObject.optString("createUser"));
		transactionRecord.setCreatetimelong(jObject.optLong("createtimelong"));
		transactionRecord.setCreateuser(jObject.optInt("createuser"));
		transactionRecord.setExt1(jObject.optString("ext1"));
		transactionRecord.setExt2(jObject.optString("ext2"));
		transactionRecord.setExt3(jObject.optString("ext3"));
		transactionRecord.setExt5(jObject.optString("ext5"));
		transactionRecord.setId(jObject.optInt("id"));
		transactionRecord.setModifytimelong(jObject.optLong("modifytimelong"));
		transactionRecord.setModifyuser(jObject.optInt("modifyuser"));
		transactionRecord.setOrderId(jObject.optInt("orderid"));
		transactionRecord.setPerPrice(jObject.optInt("perPrice"));
		transactionRecord.setPrice(jObject.optInt("price"));
		transactionRecord.setProductName(jObject.optString("productName"));
		transactionRecord.setProductId(jObject.optInt("productid"));
		transactionRecord.setShopName(jObject.optString("shopName"));
		transactionRecord.setShopid(jObject.optInt("shopid"));
		transactionRecord.setUserid(jObject.optInt("userid"));
		return transactionRecord;
	}

	private static Favorite JsonToFavorite(JSONObject jObject) {
		// TODO Auto-generated method stub
		Favorite favorite = new Favorite();
		favorite.setAddition(jObject.optString("addition"));
		favorite.setCreateUser(jObject.optString("createUser"));
		favorite.setCreatetimelong(jObject.optLong("createtimelong"));
		favorite.setCreateuser(jObject.optInt("createuser"));
		favorite.setModifytimelong(jObject.optLong("modifytimelong"));
		favorite.setModifyuser(jObject.optInt("modifyuser"));
		favorite.setProductName(jObject.optString("targetName"));
		favorite.setProductId(jObject.optInt("targetId"));
		favorite.setUserid(jObject.optInt("userid"));
		favorite.setTargetType(jObject.optInt("targetType"));
		favorite.setId(jObject.optInt("id"));
		if (jObject.optString("targetPhoto").length()>2) {
			favorite.setTargetPhoto(IMG_URL_PREFIX+jObject.optString("targetPhoto"));
		}
		else {
			favorite.setTargetPhoto(jObject.optString("targetPhoto"));
		}
		favorite.setUsername(jObject.optString("username"));
		
		return favorite;
	}
	
	private static Order JsonToOrder(JSONObject jObject) {
		// TODO Auto-generated method stub
		Order order = new Order();
		order.setAddition(jObject.optString("addition"));
		order.setComment(jObject.optString("comment"));
		order.setCoupon(jObject.optInt("coupon"));
		order.setCreateUser(jObject.optString("createUser"));
		order.setCreatetimelong(jObject.optLong("createtimelong"));
		order.setCreateuser(jObject.optInt("createuser"));
		order.setExt1(jObject.optString("ext1"));
		order.setExt2(jObject.optString("ext2"));
		order.setExt3(jObject.optString("ext3"));
		order.setExt4(jObject.optString("ext4"));
		order.setExt5(jObject.optString("ext5"));
		order.setExtInt1(jObject.optInt("extInt1"));
		order.setExtInt2(jObject.optInt("extInt2"));
		order.setExtInt3(jObject.optInt("extInt3"));
		order.setExtInt4(jObject.optInt("extInt4"));
		order.setExtInt5(jObject.optInt("extInt5"));
		order.setFinalPrice(jObject.optInt("finalPrice"));
		order.setId(jObject.optInt("id"));
		order.setModifytimelong(jObject.optLong("modifytimelong"));
		order.setModifyuser(jObject.optInt("modifyuser"));
		order.setPrice(jObject.optInt("price"));
		order.setStatus(jObject.optInt("status"));
		order.setUserid(jObject.optInt("userid"));
		order.setUsername(jObject.optString("username"));
		return order;
	}
	
	private static KiklinkMessage JsonToMessage(JSONObject jObject) {
		// TODO Auto-generated method stub
		KiklinkMessage kiklinkMessage = new KiklinkMessage();
		kiklinkMessage.setAddition(jObject.optString("addition"));
		kiklinkMessage.setCreateUser(jObject.optString("createUser"));
		kiklinkMessage.setCreatetimelong(jObject.optLong("createtimelong"));
		kiklinkMessage.setCreateuser(jObject.optInt("createuser"));
		kiklinkMessage.setId(jObject.optInt("id"));
		kiklinkMessage.setModifytimelong(jObject.optLong("modifytimelong"));
		kiklinkMessage.setModifyuser(jObject.optInt("modifyuser"));
		kiklinkMessage.setStatus(jObject.optInt("status"));
		kiklinkMessage.setContent(jObject.optString("content"));
		kiklinkMessage.setContenttype(jObject.optInt("contenttype"));
		kiklinkMessage.setFromuserid(jObject.optInt("fromuserid"));
		kiklinkMessage.setFromusername(jObject.optString("fromusername"));
		if (jObject.optString("fromuserphoto").length()>2) {
			kiklinkMessage.setFromuserphoto(IMG_URL_PREFIX+jObject.optString("fromuserphoto"));
		}
		else {
			kiklinkMessage.setFromuserphoto(jObject.optString("fromuserphoto"));
		}
		kiklinkMessage.setMessagetype(jObject.optInt("messagetype"));
		kiklinkMessage.setTouserid(jObject.optInt("touserid"));
		kiklinkMessage.setTousername(jObject.optString("tousername"));

		if (jObject.optString("touserphoto").length()>2) {
			kiklinkMessage.setTouserphoto(IMG_URL_PREFIX+jObject.optString("touserphoto"));
		}
		else {
			kiklinkMessage.setTouserphoto(jObject.optString("touserphoto"));
		}
		
		return kiklinkMessage;
	}

}
